#include "ObjectPool.h"
#include "ConcurrentAlloc.h"
#include "ThreadCache.h"

void Alloc1()
{
	for (int i = 0; i < 5; ++i)
	{
		void* ptr = ConcurrentAlloc(6);
	}
}

void Alloc2()
{
	for (int i = 0; i < 5; ++i)
	{
		void* ptr = ConcurrentAlloc(7);
	}
}

void TLSTest()
{
	std::thread t1(Alloc1);
	t1.join();

	std::thread t2(Alloc2);
	t2.join();
}

void TestConcurrentAlloc()
{
	void* ptr[7];
	ptr[0] = ConcurrentAlloc(5);
	ptr[1] = ConcurrentAlloc(6);
	ptr[2] = ConcurrentAlloc(7);
	ptr[3] = ConcurrentAlloc(8);
	ptr[4] = ConcurrentAlloc(9);
	ptr[5] = ConcurrentAlloc(10);
	ptr[6] = ConcurrentAlloc(11);

	ConcurrentFree(ptr[0], 5);
	ConcurrentFree(ptr[1], 6);
	ConcurrentFree(ptr[2], 7);
	ConcurrentFree(ptr[3], 8);
	ConcurrentFree(ptr[4], 9);
	ConcurrentFree(ptr[5], 10);
	ConcurrentFree(ptr[6], 11);
}

int main()
{
	// TLSTest();
	TestConcurrentAlloc();
	return 0;
}